import DKVui from "dk-vui"
import 'dk-vui/dist/style.css'
import 'vxe-table/lib/style.css'
import tableFormApi from '@/api/tableForm'
import { warehouse, supplier, platforms, warehouseList, role } from '@/api/public'
import request from '@/utils/request'
import { upload } from '@/api/public'
import keepStore from "@/store/modules/keepalive";
import { useRouter } from 'vue-router'


const get = (url, params) => {
  return request({
    url,
    method: 'get',
    params
  })
}

const post = (url, params) => {
  return request({
    url,
    method: 'post',
    params
  })
}

export default function (app) {
  app.use(DKVui)
  DKVui.setup({
    keepStore,
    useRouter,
    table: {
      scrollHideForm: true,
      formConfig: {
        proxy: {
          mainKey: 'sc_id', // 主键
          query: ({ model_type }) => tableFormApi.query({ model_type }),
          // model_type 类型/ name 保存名称 / sc_id 主键 / conditions保存条件
          save: ({ model_type, name, sc_id, conditions }) => tableFormApi.save({ model_type, name, sc_id, conditions }),
          remove: ({ sc_id }) => tableFormApi.remove({ sc_id })
        }
      }
    },
    select: {
      types: {
        period: () => get('/v1/supplier/supplier/get-period'), // 结算方式
        contract1: () => get('/v1/purchase-config/contract-template/get-template-id-option', { doc_type: 1 }), // 采购合同
        contract2: () => get('/v1/purchase-config/contract-template/get-template-id-option', { doc_type: 2 }), // 备料合同
        contract3: () => get('/v1/purchase-config/contract-template/get-template-id-option', { doc_type: 3 }), // 开票合同
        contract4: () => get('/v1/purchase-config/contract-template/get-template-id-option', { doc_type: 4 }), // 开票清单
        contract5: () => get('/v1/purchase-config/contract-template/get-template-id-option', { doc_type: 5 }), // 送货清单
        contract6: () => get('/v1/purchase-config/contract-template/get-template-id-option', { doc_type: 6 }), // 开票明细
        email: () => get('/v1/email/email/template-option'), // 邮箱模板
        logistics: () => get('/v1/purchase-config/logistics-config/get-logistics'), // 物流服务商
        demandChange: () => post('v1/purchase-demand/purchase-demand-change/get-change-option'), // 备库需求变更
        warehouse156: () => warehouse({ status: 1, wms_attribute: '1,5,6' }), // 仓库1,5,6
        warehouse, // 仓库
        warehouseList, // 仓库平台
        supplier, // 供应商
        supplierName: () => supplier().then(res => res.map(d => ({label: d.label, value: d.label}))), // 供应商name
        platforms, // 平台
        role, // 角色
      }
    },
    batchInput: {
      rows: 2000
    },
    upload: {
      upload,
      size: 144
    }
  })
}